package com.eternal.base.data;

import com.eternal.base.data.ble.BleController;
import com.eternal.base.data.ble.BleServer;
import com.eternal.base.data.ble.IBleControl;
import com.eternal.base.data.source.DeviceSource;
import com.eternal.base.data.source.HistorySource;
import com.eternal.base.data.source.IDeviceSource;
import com.eternal.base.data.source.IHistorySource;
import com.eternal.base.data.source.ILogSource;
import com.eternal.base.data.source.INotificationSource;
import com.eternal.base.data.source.LogSource;
import com.eternal.base.data.source.NotificationSource;

/**
 * Created by Administrator
 * On 2020/4/24
 * Description:
 *
 * @author Administrator
 */
public class RepositoryInjection {
    private static IBleControl control;

    private static IBleControl getBleControl() {
        if (control == null) {
            control = new BleController(BleServer.getInstance());
        }
        return control;
    }

    public static DeviceRepository providerDeviceRepository() {
        return DeviceContainer.repository;
    }

    public static NotificationRepository providerNotificationRepository() {
        return NotificationContainer.repository;
    }

    public static HistoryRepository providerHistoryRepository() {
        return HistoryContainer.repository;
    }

    public static LogRepository providerLogRepository() {
        return LogContainer.repository;
    }

    private static class DeviceContainer {
        private static DeviceRepository repository;

        static {
            IDeviceSource source = new DeviceSource();
            repository = new DeviceRepository(source, getBleControl());
        }
    }

    private static class NotificationContainer {
        private static NotificationRepository repository;

        static {
            INotificationSource source = new NotificationSource();
            repository = new NotificationRepository(source, getBleControl());
        }
    }

    private static class HistoryContainer {
        private static HistoryRepository repository;

        static {
            IHistorySource source = new HistorySource();
            repository = new HistoryRepository(source, getBleControl());
        }
    }

    private static class LogContainer {
        private static LogRepository repository;

        static {
            ILogSource source = new LogSource();
            repository = new LogRepository(source, getBleControl());
        }
    }
}
